package testcase;

import card.Card;
import io.ConsoleIO;
import junit.framework.TestCase;

public class CardTest extends TestCase {
	
	// override Game IO
	private class StubIO extends ConsoleIO{
		
		public String lastPrint;
		
		public void print(String s) {
			lastPrint = s;
		}
		
		public void println(String s) {
			lastPrint = s;
		}
	}
	
	// Test case for GameIO's print function
	public void testGameIOPrint(){
		String str = "Hello world!!!";
		io.print(str);
		assertEquals(io.lastPrint, str);
	}
	
	private StubIO io;
	private Card card1;
	private Card card2;

	/**
	* Sets up the test fixture.
	*
	* Called before every test case method.
	*/

	public void setUp() {		
		io = new StubIO();
		card1 = new Card();
		card2 = new Card();
	}

	/**
	* Tears down the test fixture.
	*
	* Called after every test case method.
	*/
	public void tearDown() { }

	// Test case 1: suit = NULL, value = NULL
	public void  testNoCardData() {
		card1 = new Card();
		io.print(card1, 0);
		assertEquals(io.lastPrint, "Card's data is not present.");

	}

	// Test case 2: suit = s, value = A
	public void testCard_sA(){
		card1 = new Card();
		card1.setSuit('s');
		card1.setValue('A');
		io.print(card1, 0);
		assertEquals(io.lastPrint, "0.(sA) ");
	}
	
	// Test case 3: test the compare() function if it return true correctly
	public void testCompareTrue(){

		card1 = new Card('s', 'A');
		card2 = new Card(card1);
		assertEquals(card1.compare(card2), true);

		card1.setSuit('s');
		card1.setValue('A');
		card2.setSuit('s');
		card2.setValue('2');
		assertEquals(card1.compare(card2), false);

		card1.setSuit('s');
		card1.setValue('A');
		card2.setSuit('h');
		card2.setValue('A');
		assertEquals(card1.compare(card2), false);

		card1.setSuit('s');
		card1.setValue('A');
		card2.setSuit('h');
		card2.setValue('2');
		assertEquals(card1.compare(card2), false);
		
	}

	// Test case 4: test the compare() function if it return false correctly
	public void testCompareFalse(){

		card1 = new Card();
		card2 = new Card();

		card1.setSuit('s');
		card1.setValue('A');
		card2.setSuit('h');
		card2.setValue('2');
		assertEquals(card1.compare(card2), false);
	}
	
	// Test case 5: test the clear() function
	public void testClear(){

		card1 = new Card();
		card1.setSuit('s');
		card1.setValue('A');
		card1.clear();
		io.print(card1, 0);
		assertEquals(io.lastPrint, "Card's data is not present.");

	}
}